#include "PaintVisitor.h"
#include "PointTranslator.h"
#include "../model/UMLBox.h"
#include "../model/UMLLine.h"

PaintVisitor::PaintVisitor(const PointTranslator& trans, QPainter& painter,
		const std::set<UMLObject*>& selected,
		const std::set<UMLObject*>& ghosts)
	: _trans(trans), _painter(painter), _selected(selected), _ghosts(ghosts)
{
}

void PaintVisitor::visit(UMLBox& data)
{
	// We subtract (1,1) off the paint size because of Qt's rules for painting
	// rectangles.
	static const QSize one(1, 1);

	QRect rect(_trans.toscreen(data.position()),
			_trans.toscreen(data.size()) - one);

	_painter.setPen(penColor(data));
	_painter.drawRect(rect);
	_painter.drawText(rect, Qt::AlignTop,
			data.text().fullText(), NULL); // TODO: real text
}

void PaintVisitor::visit(UMLLine& data)
{
	QRect rect(_trans.toscreen(data.position()),
			_trans.toscreen(data.size()));

	_painter.drawLine(rect.topLeft(), rect.bottomRight());
	// TODO: paint lines for real
	
}

QColor PaintVisitor::penColor(UMLObject& obj)
{
	if (_selected.find(&obj) != _selected.end())
		return Qt::blue;

	if (_ghosts.find(&obj) != _ghosts.end())
		return Qt::gray;

	return Qt::black;
}

